#include <cstdlib>
using namespace std;
class _2048{
private:
	long* board;
	int n;
	
	void init_board(){//col,row
		board=new long[n];
		for(long i=0;long<n;long++)
			board[n]=new long[n];
	}
	
	int random_value(){
		int result=random(10);
		if(result<5)result=2;
		else result=4;
		return result;	
	}
	
	void random_set(){
		long col=random(0,n);
		col=col-col%1;
		long row=random(0,n);
		row=row-col%1;
		if(!board[col][row])
			random_position();
		else(board[col][row]=random_value();
		return;
	}
	
	void delete_col_zero(long col,bool method){
		static long* cache=new long[col];
		long o=0,i=0;
		while(i<n){
			if(board[col][i]!=0){
				cache[o]=board[col][i];
				o++;
			}
			i++;
		}
		for(int i=0;i<n;i++)
			board[col][i]=0;
		if(method)
			for(long p=0;p<o;p++)
				board[col][p]=cache[p];
		else
			for(long p=o;p>-1;p--)
				for(long q=n-1;q>-1;q--)
					board[col][q]=cache[p];
		return;
	}
	
	void proc_col(long col,bool method){
		delete_col_zero(col,method)
		static long* cache=new long[col];
		if(method){
			long counter=0;
			while(counter+1>n-1){
				if(board[col][counter]==board[col][counter+1]||board[col][counter]!=0){
					board[col][counter]=2*board[col][counter];
					board[col][counter+1]=0;
					delete_col_zero(col,method);
				}
				counter++;
		}
		random_set();
	}
public:
    _2048();
    _2048(unsigned int);

    void slide_up();
    void slide_down();
    void slide_left();
    void slide_right();

    bool is_game_over();
    void reset();
    void reset(unsigned int);

    node* get_board();
    unsigned int get_board_size();
    void display(void (*)(vector<node>*));
};

_2048::_2048(){
	init_board();
	random_set();
}

_2048::_2048(unsigned int o){
	if(o>1&&o%2=0){
		n=o;
		init_board();
		random_set();
	}
}

_2048::slide_up(){
}